﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Ozone.Views.Widget
{
    /// <summary>
    /// UCClock1.xaml 的交互逻辑
    /// </summary>

    public partial class UCClock1 : UserControl
    {
        //计时器
        Timer timer = new Timer(1000);
        public UCClock1()
        {
            InitializeComponent();

            lblDate.Content = DateTime.Now.ToString("yyyy年MM月dd日");
            lblTime.Content = DateTime.Now.ToString("HH:mm:ss");
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Enabled = true;

        }

        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //UI异步更新
            this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
            {
                lblDate.Content = DateTime.Now.ToString("yyyy年MM月dd日");
                lblTime.Content = DateTime.Now.ToString("HH:mm:ss");
            }));
        }

    }
}
